package net.huashitong.ssydt.provider.money.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.huashitong.ssydt.PaginationResult;
import net.huashitong.ssydt.money.entity.SsMoneyGoldBag;
import net.huashitong.ssydt.money.entity.vo.SsMoneyGoldBagInVO;
import net.huashitong.ssydt.money.entity.vo.SsMoneyGoldBagQueryInVO;
import net.huashitong.ssydt.provider.money.service.SsMoneyGoldBagService;
import net.huashitong.ssydt.provider.web.model.Result;
import net.huashitong.ssydt.provider.web.utils.ResultUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 金币套餐数据服务
 *
 * @author hemj
 * @version 2017/8/15
 */
@Api(value = "/money/gold/bags", tags = {"金币套餐包（后台）"})
@RestController
@RequestMapping("/money/gold/bags")
public class SsMoneyGoldBagController {
    @Autowired
    private SsMoneyGoldBagService ssMoneyGoldBagService;

    @ApiOperation(value = "新增金币套餐包", notes = "根据传入条件新增记录")
    @PostMapping
    public Result<String> post(@Valid @RequestBody SsMoneyGoldBagInVO ssMoneyGoldBagInVO) {
        SsMoneyGoldBag ssMoneyGoldBag = new SsMoneyGoldBag();
        BeanUtils.copyProperties(ssMoneyGoldBagInVO, ssMoneyGoldBag);
        ssMoneyGoldBagService.insert(ssMoneyGoldBag);
        return ResultUtils.getSuccessResults();
    }

    @ApiOperation(value = "金币套餐包列表", notes = "金币套餐包列表")
    @GetMapping
    public Result<PaginationResult<SsMoneyGoldBag>> getList(@ModelAttribute SsMoneyGoldBagQueryInVO ssMoneyGoldBagQueryInVO) {
        return ResultUtils.getSuccessResults(ssMoneyGoldBagService.paginationQuery(ssMoneyGoldBagQueryInVO));
    }

    @ApiOperation(value = "获取金币套餐", notes = "根据id取对象")
    @GetMapping("/{bagsId}")
    public Result<SsMoneyGoldBag> get(
            @ApiParam(required = true, value = "套餐包id") @PathVariable("bagsId") Long bagsId) {
        return ResultUtils.getSuccessResults(ssMoneyGoldBagService.getById(bagsId));
    }

    @ApiOperation(value = "修改金币套餐", notes = "根据传入条件修改信息")
    @PutMapping("/{bagsId}")
    public Result<String> put(
            @ApiParam(required = true, value = "套餐包id") @PathVariable("bagsId") Long bagsId,
            @Valid @RequestBody SsMoneyGoldBagInVO ssMoneyGoldBagInVO) {
        SsMoneyGoldBag ssMoneyGoldBag = new SsMoneyGoldBag();
        BeanUtils.copyProperties(ssMoneyGoldBagInVO, ssMoneyGoldBag);
        ssMoneyGoldBag.setId(bagsId);
        ssMoneyGoldBagService.updateById(ssMoneyGoldBag);
        return ResultUtils.getSuccessResults();
    }

    @ApiOperation(value = "删除金币套餐", notes = "根据id删除对象")
    @DeleteMapping("/{bagsId}")
    public Result<String> delete(
            @ApiParam(required = true, value = "套餐包id") @PathVariable("bagsId") Long bagsId) {
        ssMoneyGoldBagService.deleteById(bagsId);
        return ResultUtils.getSuccessResults();
    }

}
